<?php
class kurse_model extends CI_Model {

	public function __construct()
	{
		$this->load->database();
	}
	
	public function get_kurse()
	{
		$query = $this->db->get('kurse');
		return $query->result_array();		
	}
	
	public function get_kurse_id($kurseid)
	{
		#$this -> db -> select('ID','Beschreibung','Fach');
   		$this -> db -> from('kurse');
		$this -> db -> where('Code', $kurseid);
		
		$query = $this -> db -> get();
		
		return $query->row_array();
	}
	
	public function set_kurse()
	{
		$this->load->helper('url');
		$code = url_title($this->input->post('Code'), 'dash', TRUE);
		$data = array(
			'Code' => $code,
			'Beschreibung' => $this->input->post('Beschreibung'),
			'Anzahl' => $this->input->post('Anzahl')
		);

		return $this->db->insert('kurse', $data);
	}
	
	public function validate_kurse($kurseid)
	{
		$this->load->helper('url');
		
		$data = array(
			'Beschreibung' => $this->input->post('Beschreibung'),		
			'Anzahl' => $this->input->post('Anzahl')
		);

		$where = array('Code' => $kurseid);
		return  $this->db->update('kurse',$data,$where);
	}
	
	public function get_all($limit,$offset)
	{
		$this->db->limit($limit,$offset);
		$query = $this->db->get('kurse');
		return $query->result_array();
	}

	public function get_count()
	{
		return $this->db->count_all_results('kurse');
	}
}
?>